package ToStringmethod;

public class tostring {
    public static void main(String[] args) {
       /*
       Object的tostring()源码
      //getClass().getName() 类的全类名(包名+类名)
      //Integer.toHexString(hashCode())将对象的hashcode值转换为16进制的字符串
       public String toString() {
            return getClass().getName() + "@" + Integer.toHexString(hashCode());
        }
        */

        Monster monster = new Monster("hubiao", "saodi", 2000);
        System.out.println(monster.toString());

        //当直接输出一个对象的时候，tostring方法会被默认调用
        System.out.println("==当直接输出一个对象的时候，tostring方法会被默认调用==");
        System.out.println(monster);
        tostring tostring = new tostring();
        System.out.println(tostring);
    }
}
class Monster{
    private String name;
    private String job;
    private double salary;

    public Monster(String name, String job, double salary) {
        this.name = name;
        this.job = job;
        this.salary = salary;
    }

    //重写tostring方法
    //使用快捷键即可生成Alt+insert
    @Override
    public String toString() {
        return "Monster{" +
                "name='" + name + '\'' +
                ", job='" + job + '\'' +
                ", salary=" + salary +
                '}';
    }
}